package com.hcrazy.manchester.app.controllers.member;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.hcrazy.manchester.app.services.ForumRuleService;
import com.hcrazy.manchester.app.services.InitService;
import com.hcrazy.manchester.app.utils.Log;

@Controller
@RequestMapping("/admin/member")
public class ForumRuleController {
	
	@Autowired
	private ForumRuleService ruleService;
	
	@RequestMapping(value="/forumRule")
	public void userGroup(Model model){
		try {
			model.addAttribute("rules",ruleService.getAllRules());
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
		}
	}
	
	/**
	 * 提交信息内容
	 * @param simple
	 * @return
	 */
	@RequestMapping(value="/forumRule",method=RequestMethod.POST)
    public String updateRule(@RequestParam String ruleStr,Model model,HttpServletRequest req){
		try {
			ruleService.updateForumRule(ruleStr);
			//更新forumRules
			InitService.forumRules = ruleService.getAllRulesInMap();
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			model.addAttribute("message", e.getMessage());
			return "/admin/failed";
		}
		return "redirect:/admin/member/forumRule";
    }
	
}
